package com.rmb.util;

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.alibaba.fastjson.JSON;
import com.rmb.entity.TaskExcel;
import lombok.extern.slf4j.Slf4j;

import java.util.ArrayList;
import java.util.List;

/**
 * @author excel监听器
 */
@Slf4j
public class ExcelModelListener extends AnalysisEventListener<TaskExcel> {

    /**
     * 自定义用于暂时存储data
     */
    private List<TaskExcel> datalist = new ArrayList<>();

    @Override
    public void invoke(TaskExcel data, AnalysisContext context) {
        log.info("解析第一条数据：{}",JSON.toJSONString(data));
        log.info("id:{}",data.getId());

        doSomething(data);
    }

    private void doSomething(TaskExcel user) {
        log.info("处理数据！");
    }

    @Override
    public void doAfterAllAnalysed(AnalysisContext context) {
       log.info("所有数据解析完成！");
    }

    public List<TaskExcel> getDataList() {
        return datalist;
    }

    public void setDataList(List<TaskExcel> dataList) {
        this.datalist = dataList;
    }

}
